define(function(require,exports,module) {
    var myPub = require('./public');
    var payPub = require('./submit_pay');
    var globalBuySea = require('./submit_orderGlobal_sea'); //引入身份验证js
    //var buniessConpon = require('./submit_coupon_business'); //引入商家优惠券
    var $iTotalPrice = $('.js_totalPrice'); 	            //产品总价格
    var $iFinalPayPrice = $('.js_finalPayPrice'); 	    //产品最终支付价格
    var $totalDisCountPrice = $('.js_totalDiscountPrice');
    var $chooseAddress = $(".js_userAddr");   // 选择地址
    var $chosePayType = $('.js_myPayType');     // 支付方式

    var $submitBtn = $(".js_btnPay");           // 提交支付按钮
    var $orderForm = $('#orderForm');           // 需要支付的表单

    // 校验礼品卡的地方
    var oInputMoney = $('.js_inputMoney');		//输入框
    var oUseMoneytxt = $('.js_useMoneytxt');	//最终金额显示位置

    var $memberPointCost = $('.jsMemberPointCost');  // 积分抵扣区域
    var oSwitchBtn = $('.js_switchBtn'); 			// 滑动按钮框

    var $sfMember = $('.jsSFMember');  // 顺丰会员
    var oiDCard = $('.js_iDCard');                  // 身份证信息节点

    var $sellerList = $('.js_carListBox');       //所有的卖家

    var oyueCost = $('.js_yueCost');            // 余额
    var olpkCost = $('.js_lpkCost');            // 礼品卡
    var ofanXianBtn = $('.js_fanxian');         // 购物返现
    var oUseCouponBus = $('.js_useCouponBus');  // 优惠券
    var oLpkBtn = $('.js_lpkBtn');
    var $isJifen = $('#isJifen'); //判断是否是积分商品

    var $canBuy = $('#canBuy'); //判断是否可以购买会员积分

    var buyProductList = []; // 所有商品
    var subtotalList = []; // 所有商品小计价格

    var oAddrBoxShow = $('.js_addrBoxShow');                // 顶部地址栏
    var oFooterAddress = $('.js_footerAddress');            // 底部地址栏
    var oTaxFinal = $('.js_taxFinal');                      // 商品税费
    var oFreight = $('.js_freight');                        // 运费标签

    var oCalSum = $('.js_calSum');

    var totalPrice = 0;
    var total = 0;
    var platformCouponPrice = 0;
    var sfMemberCutPrice = 0;
    var memberPointPrice = 0;
    var yuePriceFinal = 0;
    var lpkFinal = 0;
    var useGiftPrice = 0;
    var finalPrice = 0;
    var allTotalPrice = 0;
    var platformBuisneCouponPrice = [];      //商家优惠券使用的金额
    var platformBuisneCouponId = [];         // 商家优惠券的Id
    var busnieCouArr = [];
    var nGoodsList = [];        // 所有商品类型
    var nTaxPrice = 0;                       // 商品税费
    var nFreight = 0;                        // 总运费

    var platformCouponId = 0;
    var $texRi = $('.addInvoiceMess > .texRi');
    var oBllingText = $('.js_billingText');      // 发票信息展示

    // var JSESSIONID = myPub.getCookie("JSESSIONID");
    // var userInfo = myPub.getCookie("ddj-userInfo");
    // var token = myPub.getCookie("token");
    // alert("JSESSIONID :" +JSESSIONID );
    // alert("userInfo:" +userInfo );
    // alert("token:" + token);

    // 计算运费
    if(oFreight && oFreight.length > 0){
        nFreight = oFreight.attr('data-freight')*1
    }


    //如果是积分商品且不满足购买条件，对提交按钮置灰且不可点击
    if($isJifen.val() && $canBuy.val() == 'false'){
        //将按钮置灰
        $submitBtn.find('button').removeClass('btn_Bgred').addClass('btn_Bggray');
    }

    // 如果商品有税费
    if(oTaxFinal && oTaxFinal.length>0){
        // BC税费商品只能从立即购买进入确认订单页，所以页面上只能有一个商品，也有一个数量
        nTaxPrice = oTaxFinal.text()*1;
    }else{
        nTaxPrice = 0;
    }

    initAllPrice();
    calcAndShowPrice();
    // 初始化所有价格计算参数
    function initAllPrice() {
        var oAllPrice = {};       // 储存所有的价格与相应的商家优惠券优惠的金额
        var buniesCon = 0;        // 商家优惠券的金额
        var buniesConarr = [];
        subtotalList = [];
        nGoodsList = [];
        totalPrice = 0;
        allTotalPrice = 0;
        $sellerList.each(function () {
            var $sellerBox = $(this);
            buyProductList = [];
            var supplierId = parseInt($sellerBox.find('.js_storeOwner').attr("data-supplierId"));
            $sellerBox.find('.js_goodsList li').each(function () {
                var $goodsLi = $(this);
                var $goodsArea = $goodsLi.find('.js_carListArea');
                var goodsId = parseInt($goodsArea.attr("data-goodsId"));
                var productId = parseInt($goodsArea.attr("data-productId"));
                var goodsFinalPrice = parseFloat($goodsArea.find('.js_goodsPrice').attr("data-finalPrice"));
                var quantity = parseInt($goodsArea.find('.js_quantity').attr("data-quantity"));
                var buyProduct = {supplierId:supplierId,goodsId:goodsId,productId:productId,quantity:quantity,price:goodsFinalPrice};
                nGoodsList.push(1);
                buyProductList.push(buyProduct);
            });
            // 如果有商家优惠券
            var nIsBusnies = $sellerBox.find('.js_useCouponBus');
            if(nIsBusnies.length >0){
               // var maxCostMoney = $sellerBox.find('.js_businessPay ').text();
                var maxCostMoney = $sellerBox.find('.js_businessPay').attr('data-businePrice');
                buniesCon = maxCostMoney;
            }else{
                buniesCon = 0
            }
            subtotalList.push(buyProductList);
            buniesConarr.push(buniesCon);
        });
        oAllPrice = {
            subtotalList : subtotalList,
            buniesCon : buniesConarr
        };
        for(var j = 0;j < oAllPrice.subtotalList.length;j++){
            var nCalSum = oAllPrice.subtotalList[j];
            total = 0;
            for(var i = 0;i<oAllPrice.subtotalList[j].length;i++){
               var totalbranch = (nCalSum[i].price*1) * (nCalSum[i].quantity*1);
                total += totalbranch;
            }
            var nconponBuines = 0;
            if(total < oAllPrice.buniesCon[j]){
                nconponBuines = 0
            }else{
                nconponBuines = oAllPrice.buniesCon[j]
            }
            allTotalPrice += total;
            total = Math.round((total*1 - nconponBuines*1)*100)/100;
            oCalSum.eq(j).text(total);
            totalPrice += total
        }
        if(totalPrice >= sfMemberCutPrice){
            totalPrice = totalPrice - sfMemberCutPrice;
        }else{
            sfMemberCutPrice = totalPrice;
            totalPrice = 0;
        }

        return totalPrice
    }
    exports.initAllPrice = initAllPrice;


    // 有商家优惠券的情况下
    /**
     * 商家优惠券使用方法
     */
   /* function busineConPrice() {
        calcAndShowPrice();
    }
    exports.busineConPrice = busineConPrice;
    function busineCost() {
        if(oUseCouponBus.length >0){
            console.log(oBusinessPay.length);
            for(var i = 0;i < oBusinessPay.length;i++){
                var maxCostMoney = oBusinessPay.eq(i).attr("data-maxBusineMoney")*1;

                nBusineConFinal += Math.min(nCalSum,maxCostMoney);
                console.log(Math.min(nCalSum,maxCostMoney))
            }
            console.log(nBusineConFinal)
            //var maxCostMoney = oBusinessPay.attr("data-maxBusineMoney")*1;
            //var nCalSum = oCalSum.attr("data-calSum")*1;
            //nBusineConFinal = Math.min(nCalSum,maxCostMoney);
            if(oLpkBtn.hasClass('btn_active')){
                nBusineConFinal = nowCanUseMoney;
            }else{
                nBusineConFinal = 0;
            }
            if(nBusineConFinal == 0){
                oLpkBtn.removeClass('btn_active');
            }
        }
    }*/
    /**
     * 获取最大可以使用的礼品卡金额
     */
    function calAllProduct() {
        var allProductList = []; // 所有商品
        $sellerList.each(function () {
            var $sellerBox = $(this);
            var supplierId = parseInt($sellerBox.find('.js_storeOwner').attr("data-supplierId"));
            $sellerBox.find('.js_goodsList li').each(function () {
                var $goodsLi = $(this);
                var $goodsArea = $goodsLi.find('.js_carListArea');
                var goodsId = parseInt($goodsArea.attr("data-goodsId"));
                var productId = parseInt($goodsArea.attr("data-productId"));
                var categoryId = parseInt($goodsArea.attr("data-categoryId"));
                var goodsFinalPrice = parseFloat($goodsArea.find('.js_goodsPrice').attr("data-finalPrice"));
                var quantity = parseInt($goodsArea.find('.js_quantity').attr("data-quantity"));
                var buyProduct = {supplierId:supplierId,goodsId:goodsId,productId:productId,categoryId:categoryId,quantity:quantity,finalPrice:goodsFinalPrice};
                allProductList.push(buyProduct);
            });
        });
        return allProductList;
    }
    exports.calAllProduct = calAllProduct;

    initChooseAddress();
    // 初始化选择(切换)地址的事件
    function initChooseAddress() {
        // 绑定选择地址事件
        $chooseAddress.click(function(){
            var memo = getSupplierMemo();
            var eMemo = encodeURI(encodeURI(memo));

            var isGroupBuy=$('#isGroupBuy').val();
            var groupBuyType=$('#groupBuyType').val();
            var groupBuyActivityId=$('#groupBuyActivityId').val();
            var groupBuyRecordId=$('#groupBuyRecordId').val();

            if(sellMemberId!=null && sellMemberId!="undefined"){
                window.location.href="/member/address/chooseAddress?backHref="+backHref+"&memo="+eMemo+"&sellMemberId="+sellMemberId
                    +"&isGroupBuy="+isGroupBuy+"&groupBuyType="+groupBuyType+"&groupBuyActivityId="+groupBuyActivityId+"&groupBuyRecordId="+groupBuyRecordId;
            }else{
                window.location.href="/member/address/chooseAddress?backHref="+backHref+"&memo="+eMemo
                    +"&isGroupBuy="+isGroupBuy+"&groupBuyType="+groupBuyType+"&groupBuyActivityId="+groupBuyActivityId+"&groupBuyRecordId="+groupBuyRecordId;
            }
        });
    }

    initMemo();
    // 初始化 买家留言
    function initMemo() {
        // console.log(memoData);
        var json = {};
        var memoDataArray = memoData.split("|");
        for(var idx=0;idx<memoDataArray.length;idx++){
            var memoArray = memoDataArray[idx].split(",");
            if(memoArray.length == 2){
                json[memoArray[0]] = memoArray[1];
            }
        }
        $sellerList.each(function () {
            var $sellerBox = $(this);
            var supplierId = parseInt($sellerBox.find('.js_storeOwner').attr("data-supplierId"));
            var supplierMemo = json[supplierId]?json[supplierId]:'';
            $sellerBox.find('.js_message').find("input[name='Message']").val(supplierMemo);
        });
    }

    // 买家留言清除按钮
    messageClear();
    function messageClear() {
        $sellerList.each(function (n,el) {
            var oimportMsg = $(el).find('.js_importMsg');               // 留言输入框
            var oMessageClearBtn = $(el).find('.js_messageClearBtn');   // 留言清除按钮
            oimportMsg.on('input propertychange',function () {
                if(oimportMsg.val().length >0){
                    oMessageClearBtn.show()
                }else{
                    oMessageClearBtn.hide()
                }
            });
            oMessageClearBtn.on('click',function () {
                oimportMsg.val('');
                $(this).hide()
            })
        })
    }

    /*滚动时显示底部地址栏*/
   scrollAdress();
   function scrollAdress() {
        var nAddBoxHeight = oAddrBoxShow.outerHeight(true)+20;     // 顶部地址栏的高度
        var nFooterAddress = oFooterAddress.outerHeight(true);     // 顶部地址栏的高度
        $(window).on('scroll',function () {
            var afterScroll = $(this).scrollTop();
            if(afterScroll > nAddBoxHeight){
                $('.js_addresPadd').css({
                    'padding-bottom' : nFooterAddress + 15 + 'px'
                });
                oFooterAddress.show();
            }else{
                oFooterAddress.hide();
                $('.js_addresPadd').css({
                    'padding-bottom' : 0
                })
            }
        });
   }



    /**
     * 获取所有的买家留言 json
     */
    function getSupplierMemo(){
        var memoData = [];
        $sellerList.each(function () {
            var $sellerBox = $(this);
            var supplierId = parseInt($sellerBox.find('.js_storeOwner').attr("data-supplierId"));
            var memo = $sellerBox.find('.js_message').find("input[name='Message']").val();
            memoData.push([supplierId,memo].join(','));
        });
        return memoData.join('|');
    }

    /**
     * 使用商家优惠券的调用方法
     */

    var nBuniesTotalCoup = 0;
    function useBuisneCouponPrice(couponId,arr) {
        platformBuisneCouponId = couponId;
        busnieCouArr = arr;

        calcAndShowPrice();
    }
    exports.useBuisneCouponPrice = useBuisneCouponPrice;

    /**
     * 使用优惠券的调用方法
     */
    function useCouponPrice(couponPrice,couponId) {
        platformCouponPrice = couponPrice;
        platformCouponId = couponId;
        // console.log("platformPrice %o" ,platformCouponPrice);
        calcAndShowPrice();
    }
    exports.useCouponPrice = useCouponPrice;

    /**
     * 获取最大可以使用的礼品卡金额
     */
    function getMaxGiftPrice() {
        return totalPrice - platformCouponPrice;
    }
    exports.getMaxGiftPrice = getMaxGiftPrice;

    /**
     * 设置支付方式
     */
    function choosePayType(payType) {
        // console.log("payType = %o",payType);
        $orderForm.find('input[name="payType"]').val(payType);
        calcAndShowPrice();
    }
    exports.choosePayType = choosePayType;

    /**
     * 使用礼品卡金额的方法
     */
    function useGiftMoney(giftPrice) {
        useGiftPrice = giftPrice;
        // console.log("useGiftMoney %o" ,giftPrice);
        calcAndShowPrice();
    }
    exports.useGiftMoney = useGiftMoney;

    /**
     * 检查计算礼品卡的金额
     */
    function checkGiftPrice() {
        // console.log("checkGiftPrice %o %o %o",useGiftPrice,totalPrice,platformCouponPrice,nBuniesTotalCoup)  allTotalPrice;
        if(useGiftPrice > allTotalPrice - platformCouponPrice - memberPointPrice - nBuniesTotalCoup){
            useGiftPrice = allTotalPrice - platformCouponPrice - memberPointPrice - nBuniesTotalCoup;
            oInputMoney.val(useGiftPrice);
            oUseMoneytxt.text('-￥'+ useGiftPrice);
        }
    }

    /**
     * 计算最终价格
     */
    function calcAndShowPrice() {
        $iTotalPrice.text(allTotalPrice.toFixed(2));
        // 计算会员积分和价格
        // 计算商家优惠券金额
        // 计算平台优惠券金额
        if(platformCouponId != 0){
            $orderForm.find('input[name="coupon"]').val(platformCouponId);
        }else{
            $orderForm.find('input[name="coupon"]').val("");
        }

        // 商家优惠券id传入指定位置
        if(platformBuisneCouponId.length !== 0){
           // platformBuisneCouponId = platformBuisneCouponId.join(',');
            $orderForm.find('input[name="businesCoupon"]').val(platformBuisneCouponId);
        }else{
            $orderForm.find('input[name="businesCoupon"]').val("");
        }
        // 计算商家优惠券的优惠总金额
        if(busnieCouArr.length !== 0) {
            nBuniesTotalCoup = 0;
            for (var i = 0; i < busnieCouArr.length; i++) {
                nBuniesTotalCoup += busnieCouArr[i] * 1
            }
        }else{
            nBuniesTotalCoup = 0;
        }
        // 使用余额抵扣
        yuePriceCost();
        // 使用礼金卡
       lpkCost();
        // 计算会员积分抵扣
        calcMemberPoint();
        // 计算礼品卡使用金额

        // 计算一下顺丰会员价格
        calcSFMemberPoint();

        // 校验礼品卡使用金额
        checkGiftPrice();
        $orderForm.find('input[name="deposit"]').val(useGiftPrice.toFixed(2));
        var regionId = '';
        if($('input[ name = "regionId" ]').length > 0) {
            regionId = $('input[name="regionId"]').val();
        }

        $totalDisCountPrice.text((platformCouponPrice + useGiftPrice + sfMemberCutPrice+nBuniesTotalCoup).toFixed(2));
        finalPrice = totalPrice - platformCouponPrice - memberPointPrice - useGiftPrice -yuePriceFinal-lpkFinal+nTaxPrice + nFreight;

        if($orderForm.find('input[name="payType"]').val() == 'GIFTCODE' || $orderForm.find('input[name="payType"]').val() == 'DELIVERYCODE'){
            finalPrice = 0.00;
        }


        //若最终金额为0.01，则不能使用余额抵扣，将按钮置灰
        if(finalPrice == (0.01*nGoodsList.length) && !ofanXianBtn.hasClass('btn_active')){
            ofanXianBtn.addClass('btn_distable');
            ofanXianBtn.removeClass('btn_active');
        }else{
            ofanXianBtn.removeClass('btn_distable');
        }
        $iFinalPayPrice.text(finalPrice.toFixed(2));
        transLpk();
    }
    /**
     * 使用余额的方法
     */
    function yuePrice() {
        calcAndShowPrice();
    }
    exports.yuePrice = yuePrice;
    function yuePriceCost() {
        initAllPrice();
        if(oyueCost.length > 0){
             var maxCostMoney = oyueCost.attr("data-maxCostMoney");
             //使用余额抵扣，需要支付至少0.01
             var nowCanUseMoney = Math.min((totalPrice - platformCouponPrice-(0.01*nGoodsList.length)).toFixed(2),maxCostMoney);
            if(ofanXianBtn.hasClass('btn_active')){
                yuePriceFinal = nowCanUseMoney;
                $orderForm.find('input[name="isUseBalance"]').val(true);
            }else{
                yuePriceFinal = 0;
                $orderForm.find('input[name="isUseBalance"]').val(false);
            }
            if(yuePriceFinal == 0){
                ofanXianBtn.removeClass('btn_active');
                $orderForm.find('input[name="isUseBalance"]').val(false);
            }
            $orderForm.find('input[name="balanceAmount"]').val(yuePriceFinal);
        }
    }

    /**
     * 使用礼品卡的方法
     */
    function lpkPrice() {
        calcAndShowPrice();
    }
    exports.lpkPrice = lpkPrice;
    function lpkCost() {
        if(olpkCost.length >0){
            var maxCostMoney = olpkCost.attr("data-maxCostMoney");
            var nowCanUseMoney = Math.min(Number(totalPrice - platformCouponPrice),maxCostMoney);
            if(oLpkBtn.hasClass('btn_active')){
                lpkFinal = nowCanUseMoney;
              //  $orderForm.find('input[name="isUseBalance"]').val(true);
            }else{
                lpkFinal = 0;
              //  $orderForm.find('input[name="isUseBalance"]').val(false);
            }
            if(lpkFinal == 0){
                oLpkBtn.removeClass('btn_active');
               // $orderForm.find('input[name="isUseBalance"]').val(false);
            }
            //$orderForm.find('input[name="balanceAmount"]').val(lpkFinal);
        }
        $('.js_lpkDeductionNo').text(lpkFinal);
        $orderForm.find('input[name="cardBalanceAmount"]').val(lpkFinal);
    }

    /**
     * 校验礼品卡
     */
    function transLpk() {
        var payType =$orderForm.find('input[name="payType"]').val();
        var hasGray = $('.js_myPayType').find('.ljkType').hasClass('gray');
        if("PREPAIDCARDCODE"==payType){
            $(".giftCard").hide();
            var salePrice=$('.js_finalPayPrice').html();
            G_JSON_POST("/shop/pay/showPrepaidCardPay",{salePrice:salePrice},function (data) {
                if(!data){
                    myPub.TipLayer("礼品卡余额不足","no");
                    $chosePayType.siblings().find('.js_checkBox').removeClass('active');
                    $chosePayType.eq(0).find('.js_checkBox').addClass('active');
                    $orderForm.find('input[name="payType"]').val($chosePayType.eq(0).attr("data-payType"));
                    $('.js_myPayType').find('.ljkType').addClass('gray');
                    $(".giftCard").show();

                }else{
                    $("#orderForm").eq(0).find("input[name='prepaidCard']").val("true");
                    $('#invoice').val("");
                    $texRi.hide();
                    oBllingText.addClass("noInvoiceSupport");
                    oBllingText.html("礼品卡购物暂不支持开发票");
                }
            });
        }else{
            $(".giftCard").show();
            if(hasGray){
                $('.js_myPayType').find('.ljkType').removeClass('gray');
            }
        }
    }
    
    function calcMemberPoint() {
        initAllPrice();
        if($memberPointCost.length > 0){
            var costRate = parseInt($memberPointCost.attr("data-CostRate"));
            var maxCostMoney = parseInt($memberPointCost.attr("data-maxCostMoney"));
            var nowCanUseMoney = Math.min(parseInt(totalPrice - platformCouponPrice),maxCostMoney);
            if(nowCanUseMoney <= 0){
                nowCanUseMoney = 0;
            }
            var nowCostPoint = nowCanUseMoney * costRate;
            $memberPointCost.find('.jsPointCost').html(nowCostPoint);
            $memberPointCost.find('.jsPointCostMoney').html(nowCanUseMoney);
            if(oSwitchBtn.hasClass('btn_active')){
                memberPointPrice = nowCanUseMoney;
                $orderForm.find('input[name="isUsePoint"]').val(true);
            }else{
                memberPointPrice = 0;
                $orderForm.find('input[name="isUsePoint"]').val(false);
            }
        }

    }
    /**
     * 使用会员积分的方法
     */
    function useMemberPoint() {
        calcAndShowPrice();
    }
    exports.useMemberPoint = useMemberPoint;

    /**
     * 使用顺丰会员积分的方法
     */
    function calcSFMemberPoint() {
        if($sfMember.length > 0){
            var cutPrice = parseFloat($sfMember.attr("data-cutPrice"));
            if($sfMember.find('.js_memberBtn').hasClass('btn_active')){
                sfMemberCutPrice = cutPrice;
            }else{
                sfMemberCutPrice = 0;
            }
        }
        initAllPrice();
    }

    /**
     * 使用顺丰会员积分的方法
     */
    function useSFMemberPoint() {
        calcSFMemberPoint();
    }
    exports.useSFMemberPoint = useSFMemberPoint;


    //提交订单按钮单击事件
    $submitBtn.click(function() {

        // 2018年4月19日lou增加全球购身份验证
        // 关于身份证与购买须知的判断
        if(oiDCard.length === 1) {
            if (!globalBuySea.globalBuyCheck()) {
                // console.log(2222222);
                return false;
            }
        }
        //积分商品判断不可点击
        if($isJifen.val() && $canBuy.val() == 'false'){
            return false;
        }

        // 验证地址是否已选
        if(!checkAddress()){
            return false;
        }

        // 验证是否是顺丰官微会员
        var useMember = $('.js_memberBtn').hasClass('btn_active');
        if(useMember){
            $orderForm.find("input[name='sfMemberBuy']").val(1);
        }

        // 赠送他人的验证
        if(!checkIsSongLi()){
            return false;
        }

        // 鲜花任选 检查
        checkMultiProduct();

        // 备注的设置
        var memoText = getSupplierMemo();
        $orderForm.find("input[name='memos']").val(memoText);

        // 发货时间选择
        $orderForm.find("input[name='userDeliveryTime']").val($("#goodsDeliveryDate").find("li.active").attr("value"));

        //var bljkOff = $('.js_lpkBtn').hasClass('btn_active');  // 判断是否开启礼品卡支付
        // 默认地址弹窗提醒
        if(giftOrder != null && (giftOrder == 1 ||giftOrder == 2)){
            if($(this).data("repeatclick")){
                myPub.TipLayer("请勿重复提交");
                return false;
            }
            $(this).data("repeatclick",true);
            // 送礼订单 不需要地址 直接提交订单
            toPay()
        }else if (autoDefault == 1) {
            var _tit = '请核对您的收货地址';//#666
            var comfirmMsg = $('.js_userAddr a').html();
            myPub.askLayer(comfirmMsg, function () {
                myPub.LayerCloseAll();
                toPay()
            }, function () {
            }, _tit);
        } else {
            toPay()
        }
    });

    // 判断礼品卡混合支付是否开启
    var prepaidCard = '';
    function isLpkUse(boolen) {
        if(boolen){
            prepaidCard = 'true'
        }else{
            prepaidCard = 'false'
        }
    }
    exports.isLpkUse = isLpkUse;

    /**
     * 提交支付的方法
     */
    function toPay() {


        userAction();
        if( isGrouperFree == "true" ){
            var payUrl = "/shop/nowbuy/groupFreePay";
        }else if(prepaidCard == "true"){
           var payUrl = "/prepaidCard/payFromLpkPay";
        }else{
            // var payUrl = "/shop/payment/orderPay";
            var payUrl = "/shop/payment/orderPay";
        }


        // $orderForm.find('input[name="sessionUid"]').val(token);


        var data = $orderForm.serialize();
        payPub.submitPay(payUrl,data);
    }



    // 验证地址
    function checkAddress() {
        // 送礼订单不需要地址
        if(giftOrder != null && (giftOrder == 1 ||giftOrder == 2)){
            $orderForm.find('input[name="giftOrder"]').val(giftOrder);
            return true;
        }
        if($orderForm.find('input[name="shipMobile"]').val().trim() == ""){
            myPub.TipLayer("请选择收货地址");
            return false;
        }
        return true;
    }

    //检验是否是赠送他人
    function checkIsSongLi(){
        var isSongLiValue = $orderForm.find('input[name="isSongLi"]').val();
        // console.log("isSongLiValue %o",isSongLiValue);
        if(isSongLiValue != "true"){
            $orderForm.find("input[name='buyerName']").val("");
            $orderForm.find("input[name='buyerPhoneNumber']").val("");
            return true;
        }
        var oUserName = $(".js_userName").attr("judgeBloor");
        var oUserIphone = $(".js_userIphone").attr("judgeBloor");
        if(oUserName == "true" && oUserIphone == "true" ){
            $orderForm.find("input[name='buyerName']").val($("#songliUsername").val());
            $orderForm.find("input[name='buyerPhoneNumber']").val($("#songliUserPhone").val());
            return true;
        }else if(oUserName =="false"){
            myPub.TipLayer("购买者姓名不符合规则或者为空！");
            return false;
        }else if(oUserIphone == "false"){
            myPub.TipLayer("电话号码不符合规则或者为空！");
            return false;
        }
    }

    // 检查是否是鲜花任选
    function checkMultiProduct(){
        if(typeof(xgCount) != 'undefined' && xgCount > 1 && saleModel ==1){
            $("input[name='multiProductIds']").val(multiProductIds);
            $("input[name='quantity']").val(1);
        }
    }


    // 添加用户行为
    function userAction() {

        // 添加用户行为
        var _calAllProduct = calAllProduct();
        var setActionData = [];
        var data_requestid =  $('input[name=recRequestId]').val();
        var data_goodschannel =  $('input[name=goodschannel]').val();
        var data_sceneType =  $('input[name=sceneType]').val();
        for(var i=0; i<_calAllProduct.length; i++) {
            setActionData[i] = {};
            setActionData[i].pid = _calAllProduct[i].productId * 1;
            setActionData[i].num = _calAllProduct[i].quantity * 1;
            setActionData[i].requestid = data_requestid;
            if( data_goodschannel == 'datagrand' || data_goodschannel == 'not_datagrand' ){
                setActionData[i].scenetype = 'cate';
            } else {
                setActionData[i].scenetype = data_sceneType;
            }

        }
        // console.log(setActionData)
        // ddjhoc.setData(_calAllProduct, 'buy', 'add', function () {
        //     console.log('params.buy', ddjhoc.params);
        //     ddjhoc.sendData( ddjhoc.params );
        // }, setActionData);

    }


});